package com.pentajock.docdb.gui;

import com.pentajock.docdb.colors.Colors;
//import java.lang.Object;
import java.util.Vector;
import javax.swing.JList;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.ListCellRenderer;

public class VisibleIndexList extends JList {
	//private int prevIndex = -1;
	private boolean ensureIndexIsVisible = true;
	public VisibleIndexList() {
		super();
		setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	}
	public VisibleIndexList(ListModel dataModel) {
		super(dataModel);
		setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	}
	public VisibleIndexList(Object[] listData) {
		super(listData);
		setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	}
	public VisibleIndexList(Vector<?> listData) {
		super(listData);
		setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	}
        
        @Override
	public void setCellRenderer(ListCellRenderer cellRenderer) {
		super.setCellRenderer(cellRenderer);
	}
        
        @Override
	public void setSelectedIndex(int index) {
		super.setSelectedIndex(index);
		if (ensureIndexIsVisible) super.ensureIndexIsVisible(index);
	}
	public void setEnsureIndexIsVisible(boolean isVisible) {
		ensureIndexIsVisible = isVisible;
	}
	public boolean getEnsureIndexIsVisible(boolean isVisible) {
		return ensureIndexIsVisible;
	}
	
	/* Recalculate colors incase the new L&F makes colors unreadable */
        @Override
	public void updateUI() {
		Colors.refreshColors(); 
		super.updateUI();
	}
}
		
